package com.magicrule.car.systemManage.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.magicrule.car.systemManage.configClass.RedisUtil;
import com.magicrule.car.systemManage.dao.api.BookDao;
import com.magicrule.car.systemManage.dao.api.MemberDao;
import com.magicrule.car.systemManage.model.entity.Book;
import com.magicrule.car.systemManage.model.entity.Member;
import com.magicrule.car.systemManage.model.entity.UserInfo;
import com.magicrule.car.systemManage.service.api.UserInfoServiceApi;



@RestController
@RequestMapping(value="/usermanage",produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
public class UserInfoController {

	protected static Logger log = LoggerFactory.getLogger(UserInfoController.class);  
	@Autowired
	UserInfoServiceApi userInfoService;
	
	@Autowired
	private MemberDao memberDao;

	@Autowired
	private BookDao bookDao;
	
	@Autowired
	private RedisUtil redisUtil;
	
	@RequestMapping("/hello")
    public String index(@RequestParam String name) {
        return "hello "+name+"，this is first messge";
    }
	
	@RequestMapping("/finduser")
    public UserInfo findUser(){
		int re=100/0;
		return userInfoService.selectByPrimaryKey("30cf3150-bfba-4c06-a100-168982e941a9");
    }
	
	@RequestMapping(value="/finduser2",method=RequestMethod.POST,consumes=MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UserInfo findUser2(UserInfo userInfo){
		System.out.println(userInfo.getUserid());
		return userInfoService.selectByPrimaryKey("30cf3150-bfba-4c06-a100-168982e941a9");
    }
	
	@RequestMapping("/mongotest")
    public void mongotest(){
		Member member1 = new Member();
		
		member1.setId("1");
		member1.setUsername("username1");
		member1.setPassword("password1");
		
		memberDao.save(member1);
    }
	
}